// Copyright DustedPixels.com 2008. All rights reserved.

package kroff.opt;

/**
 * @author micapolos@gmail.com (Michal Pociecha-Los)
 */
public final class ThousandToOneExecutor implements Runnable {
  private final Runnable everyTime;
  private final Runnable onceInThousand;
  private int counter = 0;

  public ThousandToOneExecutor(Runnable everyTime, Runnable onceInThousand) {
    this.everyTime = everyTime;
    this.onceInThousand = onceInThousand;
  }
  
  public void run() {
    everyTime.run();
    if (counter == 0) {
      onceInThousand.run();
    }
    counter = (counter + 1) % 1000;
  }
}
